<!DOCTYPE HTML>
<html lang="en" class="sidebar-visible no-js light">
    <head>
        <!-- Book generated using mdBook -->
        <meta charset="UTF-8">
        <title>GDScript 零基础图文入门</title>


        <!-- Custom HTML head -->
        
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="theme-color" content="#ffffff" />

        <link rel="icon" href="favicon.svg">
        <link rel="shortcut icon" href="favicon.png">
        <link rel="stylesheet" href="css/variables.css">
        <link rel="stylesheet" href="css/general.css">
        <link rel="stylesheet" href="css/chrome.css">
        <link rel="stylesheet" href="css/print.css" media="print">

        <!-- Fonts -->
        <link rel="stylesheet" href="FontAwesome/css/font-awesome.css">
        <link rel="stylesheet" href="fonts/fonts.css">

        <!-- Highlight.js Stylesheets -->
        <link rel="stylesheet" href="highlight.css">
        <link rel="stylesheet" href="tomorrow-night.css">
        <link rel="stylesheet" href="ayu-highlight.css">

        <!-- Custom theme stylesheets -->
        <link rel="stylesheet" href=".\.\mdbook-admonish.css">
        <link rel="stylesheet" href="src/css/style.css">

    </head>
    <body>
    <div id="body-container">
        <!-- Provide site root to javascript -->
        <script>
            var path_to_root = "";
            var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light";
        </script>

        <!-- Work around some values being stored in localStorage wrapped in quotes -->
        <script>
            try {
                var theme = localStorage.getItem('mdbook-theme');
                var sidebar = localStorage.getItem('mdbook-sidebar');

                if (theme.startsWith('"') && theme.endsWith('"')) {
                    localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
                }

                if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
                    localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
                }
            } catch (e) { }
        </script>

        <!-- Set the theme before any content is loaded, prevents flash -->
        <script>
            var theme;
            try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
            if (theme === null || theme === undefined) { theme = default_theme; }
            var html = document.querySelector('html');
            html.classList.remove('no-js')
            html.classList.remove('light')
            html.classList.add(theme);
            html.classList.add('js');
        </script>

        <!-- Hide / unhide sidebar before it is displayed -->
        <script>
            var html = document.querySelector('html');
            var sidebar = 'hidden';
            if (document.body.clientWidth >= 1080) {
                try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
                sidebar = sidebar || 'visible';
            }
            html.classList.remove('sidebar-visible');
            html.classList.add("sidebar-" + sidebar);
        </script>

        <nav id="sidebar" class="sidebar" aria-label="Table of contents">
            <div class="sidebar-scrollbox">
                <ol class="chapter"><li class="chapter-item expanded affix "><a href="GDScript.html" class="active">GDScript 零基础图文入门</a></li><li class="chapter-item expanded affix "><a href="ABOUT.html">关于本文</a></li><li class="chapter-item expanded "><a href="Part1/Start.html"><strong aria-hidden="true">1.</strong> 开始</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="Part1/什么是编程.html"><strong aria-hidden="true">1.1.</strong> 什么是编程</a></li><li class="chapter-item expanded "><a href="Part1/第一句代码.html"><strong aria-hidden="true">1.2.</strong> 第一句代码</a></li><li class="chapter-item expanded "><a href="Part1/脚本结构.html"><strong aria-hidden="true">1.3.</strong> 脚本结构</a></li><li class="chapter-item expanded "><a href="Part1/后续预告.html"><strong aria-hidden="true">1.4.</strong> 后续预告</a></li><li class="chapter-item expanded "><a href="Part1/资源汇总.html"><strong aria-hidden="true">1.5.</strong> 资源汇总</a></li></ol></li><li class="chapter-item expanded "><a href="Part2/Start.html"><strong aria-hidden="true">2.</strong> 基础语法</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="Part2/变量.html"><strong aria-hidden="true">2.1.</strong> 变量</a></li><li class="chapter-item expanded "><a href="Part2/数据类型.html"><strong aria-hidden="true">2.2.</strong> 数据类型</a></li><li class="chapter-item expanded "><a href="Part2/表达式与运算符.html"><strong aria-hidden="true">2.3.</strong> 表达式与运算符</a></li><li class="chapter-item expanded "><a href="Part2/强类型变量.html"><strong aria-hidden="true">2.4.</strong> 强类型变量</a></li><li class="chapter-item expanded "><a href="Part2/整活：你好XXX.html"><strong aria-hidden="true">2.5.</strong> 整活：你好XXX</a></li><li class="chapter-item expanded "><a href="Part2/代码块.html"><strong aria-hidden="true">2.6.</strong> 代码块</a></li><li class="chapter-item expanded "><a href="Part2/分支结构.html"><strong aria-hidden="true">2.7.</strong> 分支结构</a></li><li class="chapter-item expanded "><a href="Part2/作用域.html"><strong aria-hidden="true">2.8.</strong> 作用域</a></li><li class="chapter-item expanded "><a href="Part2/整活：狐狸彩票.html"><strong aria-hidden="true">2.9.</strong> 整活：狐狸彩票</a></li><li class="chapter-item expanded "><a href="Part2/循环.html"><strong aria-hidden="true">2.10.</strong> 循环</a></li><li class="chapter-item expanded "><a href="Part2/数组.html"><strong aria-hidden="true">2.11.</strong> 数组</a></li><li class="chapter-item expanded "><a href="Part2/遍历.html"><strong aria-hidden="true">2.12.</strong> 遍历</a></li><li class="chapter-item expanded "><a href="Part2/循环控制.html"><strong aria-hidden="true">2.13.</strong> 循环控制</a></li></ol></li><li class="chapter-item expanded "><a href="Part-认识面向对象/Start.html"><strong aria-hidden="true">3.</strong> 认识面向对象</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="Part-认识面向对象/方法.html"><strong aria-hidden="true">3.1.</strong> 方法</a></li><li class="chapter-item expanded "><a href="Part-认识面向对象/方法参数.html"><strong aria-hidden="true">3.2.</strong> 方法-参数</a></li><li class="chapter-item expanded "><a href="Part-认识面向对象/方法返回值.html"><strong aria-hidden="true">3.3.</strong> 方法-返回值</a></li><li class="chapter-item expanded "><a href="Part-认识面向对象/面向对象.html"><strong aria-hidden="true">3.4.</strong> 面向对象</a></li><li class="chapter-item expanded "><a href="Part-认识面向对象/类.html"><strong aria-hidden="true">3.5.</strong> 类</a></li><li class="chapter-item expanded "><a href="Part-认识面向对象/类成员.html"><strong aria-hidden="true">3.6.</strong> 类成员</a></li><li class="chapter-item expanded "><a href="Part-认识面向对象/引用类型与null.html"><strong aria-hidden="true">3.7.</strong> 引用类型与null</a></li><li class="chapter-item expanded "><a href="Part-认识面向对象/日后再深入.html"><strong aria-hidden="true">3.8.</strong> 日后再深入</a></li></ol></li><li class="chapter-item expanded "><a href="Part-引擎交互/Start.html"><strong aria-hidden="true">4.</strong> 引擎交互</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="Part-引擎交互/生命周期1.html"><strong aria-hidden="true">4.1.</strong> 生命周期1</a></li><li class="chapter-item expanded "><a href="Part-引擎交互/生命周期2.html"><strong aria-hidden="true">4.2.</strong> 生命周期2</a></li><li class="chapter-item expanded "><a href="Part-引擎交互/获取输入.html"><strong aria-hidden="true">4.3.</strong> 获取输入</a></li><li class="chapter-item expanded "><a href="Part-引擎交互/线性输入.html"><strong aria-hidden="true">4.4.</strong> 线性输入</a></li><li class="chapter-item expanded "><a href="Part-引擎交互/整活：玩家移动.html"><strong aria-hidden="true">4.5.</strong> 整活：玩家移动</a></li><li class="chapter-item expanded "><a href="Part-引擎交互/PackedScene实例化.html"><strong aria-hidden="true">4.6.</strong> PackedScene实例化</a></li><li class="chapter-item expanded "><a href="Part-引擎交互/节点操作.html"><strong aria-hidden="true">4.7.</strong> 节点操作</a></li><li class="chapter-item expanded "><a href="Part-引擎交互/整活：Fire.html"><strong aria-hidden="true">4.8.</strong> 整活：Fire</a></li><li class="chapter-item expanded "><a href="Part-引擎交互/信号.html"><strong aria-hidden="true">4.9.</strong> 信号</a></li><li class="chapter-item expanded "><a href="Part-引擎交互/组.html"><strong aria-hidden="true">4.10.</strong> 组</a></li><li class="chapter-item expanded "><a href="Part-引擎交互/整活：靶子.html"><strong aria-hidden="true">4.11.</strong> 整活：靶子</a></li><li class="chapter-item expanded "><a href="Part-引擎交互/属性导出.html"><strong aria-hidden="true">4.12.</strong> 属性导出</a></li><li class="chapter-item expanded "><a href="Part-引擎交互/整活：分数.html"><strong aria-hidden="true">4.13.</strong> 整活：分数</a></li></ol></li><li class="chapter-item expanded "><a href="Part-深入面向对象/Start.html"><strong aria-hidden="true">5.</strong> 深入面向对象</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="Part-深入面向对象/字典.html"><strong aria-hidden="true">5.1.</strong> 字典</a></li><li class="chapter-item expanded "><a href="Part-深入面向对象/脚本与类.html"><strong aria-hidden="true">5.2.</strong> 脚本与类</a></li><li class="chapter-item expanded "><a href="Part-深入面向对象/整活：敌人.html"><strong aria-hidden="true">5.3.</strong> 整活：敌人</a></li><li class="chapter-item expanded "><a href="Part-深入面向对象/封装.html"><strong aria-hidden="true">5.4.</strong> 封装</a></li><li class="chapter-item expanded "><a href="Part-深入面向对象/整活：玩家生命值.html"><strong aria-hidden="true">5.5.</strong> 整活：玩家生命值</a></li><li class="chapter-item expanded "><a href="Part-深入面向对象/继承.html"><strong aria-hidden="true">5.6.</strong> 继承</a></li><li class="chapter-item expanded "><a href="Part-深入面向对象/节点与继承.html"><strong aria-hidden="true">5.7.</strong> 节点与继承</a></li><li class="chapter-item expanded "><a href="Part-深入面向对象/重写.html"><strong aria-hidden="true">5.8.</strong> 重写</a></li><li class="chapter-item expanded "><a href="Part-深入面向对象/多态.html"><strong aria-hidden="true">5.9.</strong> 多态</a></li><li class="chapter-item expanded "><a href="Part-深入面向对象/整活：多种武器.html"><strong aria-hidden="true">5.10.</strong> 整活：多种武器</a></li><li class="chapter-item expanded "><a href="Part-深入面向对象/信号.html"><strong aria-hidden="true">5.11.</strong> 信号</a></li><li class="chapter-item expanded "><a href="Part-深入面向对象/整活：更换武器的UI提示.html"><strong aria-hidden="true">5.12.</strong> 整活：更换武器的UI提示</a></li></ol></li><li class="chapter-item expanded "><a href="Part-进阶技巧/Start.html"><strong aria-hidden="true">6.</strong> 进阶技巧</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="Part-进阶技巧/枚举.html"><strong aria-hidden="true">6.1.</strong> 枚举</a></li><li class="chapter-item expanded "><a href="Part-进阶技巧/单例-自动加载.html"><strong aria-hidden="true">6.2.</strong> 单例/自动加载</a></li><li class="chapter-item expanded "><a href="Part-进阶技巧/唯一名称.html"><strong aria-hidden="true">6.3.</strong> 唯一名称</a></li><li class="chapter-item expanded "><a href="Part-进阶技巧/load.html"><strong aria-hidden="true">6.4.</strong> load</a></li><li class="chapter-item expanded "><a href="Part-进阶技巧/定义类.html"><strong aria-hidden="true">6.5.</strong> 定义类</a></li><li class="chapter-item expanded "><a href="Part-进阶技巧/类型判断.html"><strong aria-hidden="true">6.6.</strong> 类型判断</a></li><li class="chapter-item expanded "><a href="Part-进阶技巧/静态.html"><strong aria-hidden="true">6.7.</strong> 静态</a></li><li class="chapter-item expanded "><a href="Part-进阶技巧/字符串格式化.html"><strong aria-hidden="true">6.8.</strong> 字符串格式化</a></li><li class="chapter-item expanded "><a href="Part-进阶技巧/存档与读档.html"><strong aria-hidden="true">6.9.</strong> 存档与读档</a></li><li class="chapter-item expanded "><a href="Part-进阶技巧/函数式编程.html"><strong aria-hidden="true">6.10.</strong> 函数式编程</a></li></ol></li><li class="chapter-item expanded "><a href="待整理的内容.html"><strong aria-hidden="true">7.</strong> 还没整理的内容</a></li></ol>
            </div>
            <div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
        </nav>

        <div id="page-wrapper" class="page-wrapper">

            <div class="page">
                                <div id="menu-bar-hover-placeholder"></div>
                <div id="menu-bar" class="menu-bar sticky bordered">
                    <div class="left-buttons">
                        <button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
                            <i class="fa fa-bars"></i>
                        </button>
                        <button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
                            <i class="fa fa-paint-brush"></i>
                        </button>
                        <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
                            <li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
                        </ul>
                        <button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
                            <i class="fa fa-search"></i>
                        </button>
                    </div>

                    <h1 class="menu-title"></h1>

                    <div class="right-buttons">
                        <a href="print.html" title="Print this book" aria-label="Print this book">
                            <i id="print-button" class="fa fa-print"></i>
                        </a>
                        <a href="https://github.com/Reimenn/MyGDSciprtBook" title="Git repository" aria-label="Git repository">
                            <i id="git-repository-button" class="fa fa-github"></i>
                        </a>

                    </div>
                </div>

                <div id="search-wrapper" class="hidden">
                    <form id="searchbar-outer" class="searchbar-outer">
                        <input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
                    </form>
                    <div id="searchresults-outer" class="searchresults-outer hidden">
                        <div id="searchresults-header" class="searchresults-header"></div>
                        <ul id="searchresults">
                        </ul>
                    </div>
                </div>

                <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
                <script>
                    document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
                    document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
                    Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
                        link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
                    });
                </script>

                <div id="content" class="content">
                    <main>
                        <h1 id="gdscript-零基础图文入门"><a class="header" href="#gdscript-零基础图文入门">GDScript 零基础图文入门</a></h1>
<p>各位热爱游戏的小伙伴们大家好。</p>
<p>随着 Godot 的热度越来越高，有很多无程序开发基础的小伙伴认识了 Godot，个人认为 Godot 从 4.0 版本开始，已经成为了最适合游戏开发新人上手的引擎（易上手 不等于 功能简单），她相较于 Unity 更易学习，且功能足够各位开发者实现自己的梦中游戏。</p>
<p>开发游戏通常离不开编写代码，Godot 支持的编程语言中 <code>GDScript</code> 和 <code>C#</code> 是使用最广泛的：</p>
<ul>
<li>
<p><code>C#</code> 是微软公司开发的编程语言，虽然普及率不如 <code>Java</code>、<code>Python</code> 等“超一线”语言，但其功能十分强大，且拥有“宇宙第一优雅”的编程语法，但由于它真的很强大且语法实在“优雅”，学习它会花费更多的时间与精力。</p>
</li>
<li>
<p>而 <code>GDScript</code> 听名字就知道这是 Godot 自己的编程语言，因为是为游戏开发而设计，语言中的每一项功能都是为了方便我们做游戏而诞生，因此在实现同样功能的情况下，<code>GDScript</code> 会比 <code>C#</code> 少很多代码，学习起来也更加轻松。</p>
</li>
</ul>
<p>综上所述，我更推荐新人者从 <code>GDScript</code> 上手，这将是一条轻松愉悦的学习路线。</p>
<blockquote>
<p>[!tip] 新人学编程第一大门槛：选择编程语言。</p>
<p>我这里要说：随便选一个语言就行（当然现在我推荐 GDScript 了就不要乱选了233），<strong>重要的是坚持学到最后，不要中途放弃或者换语言</strong>。其实绝大多数编程语言都是共通的，就像你学会合成铁镐子后自然就会合成钻石镐一样，当你通过本文学会 <code>GDScript</code> 后，自然也会看的懂很多其它语言的代码。</p>
</blockquote>
<blockquote>
<p>[!tip] Godot 版本</p>
<p>编写本文时 Godot 刚刚推出了 4.0 rc2，所以文中按照 4.0 版本讲解。</p>
</blockquote>

                    </main>

                    <nav class="nav-wrapper" aria-label="Page navigation">
                        <!-- Mobile navigation buttons -->

                            <a rel="next" href="ABOUT.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                                <i class="fa fa-angle-right"></i>
                            </a>

                        <div style="clear: both"></div>
                    </nav>
                </div>
            </div>

            <nav class="nav-wide-wrapper" aria-label="Page navigation">

                    <a rel="next" href="ABOUT.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                        <i class="fa fa-angle-right"></i>
                    </a>
            </nav>

        </div>

        <!-- Livereload script (if served using the cli tool) -->
        <script>
            const wsProtocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
            const wsAddress = wsProtocol + "//" + location.host + "/" + "__livereload";
            const socket = new WebSocket(wsAddress);
            socket.onmessage = function (event) {
                if (event.data === "reload") {
                    socket.close();
                    location.reload();
                }
            };

            window.onbeforeunload = function() {
                socket.close();
            }
        </script>



        <script>
            window.playground_copyable = true;
        </script>


        <script src="elasticlunr.min.js"></script>
        <script src="mark.min.js"></script>
        <script src="searcher.js"></script>

        <script src="clipboard.min.js"></script>
        <script src="highlight.js"></script>
        <script src="book.js"></script>

        <!-- Custom JS scripts -->
        <script src="src/js/style.js"></script>


    </div>
    </body>
</html>
